home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / tpflex.arc / FLEX.INT < prev    next >
Text File  |  1991-04-28  |  4KB  |  127 lines

  1. {
  2.  
  3.     flex.pas  // FlexList
  4.     4-23-90
  5.     Generic hybrid stack-queue-list-array object.
  6.  
  7.     Copyright 1990
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072
  14.  
  15.  
  16.     Anytime your Turbo Pascal application requires a stack,
  17.     queue, or linked list, simply include "flex" in its
  18.     "uses" clause.  Next declare your stack, queue, or list
  19.     as a variable of type "FlexList".  FlexList is a hybrid
  20.     stack-queue-list-array generic data structure.  Your
  21.     FlexList variable can be initialized to store any type
  22.     of data.  The FlexList object has over 30 methods for
  23.     accessing your "list" as a stack, queue, list, or array
  24.     interchangeably!  You can push, pop, ins, del, sort,
  25.     store, recall, or find to name but just a few operations.
  26.     FlexList methods allows you to access your list's data
  27.     by value (copy) or by reference (pointer) as well as to
  28.     move nodes directly between lists.  And your
  29.     application's code size won't continue to grow when you
  30.     add new types of lists either, since the FlexList object
  31.     is generic, able to hold any type of data, record or
  32.     object.  Since FlexLists are initialized at run time,
  33.     the data they hold or even their creation can be
  34.     specified at run time thus allowing your application new
  35.     dimensions of adaptibility to user inputs.  And with
  36.     FlexList you can quickly construct lists of lists or
  37.     other composite structures.  FlexList will save you
  38.     time, money, code space and headaches!
  39.  
  40.  
  41.     For example:
  42.  
  43.         var intStack : FlexList;
  44.  
  45.         begin
  46.             writeln('Count backwards from ten.');
  47.             intStack.init(sizeof(integer));
  48.             for i := 1 to 10 do
  49.                 intStack.push(i);
  50.             intStack.pop(i);
  51.             while intStack.ok do begin
  52.                 writeln(i);
  53.                 intStack.pop(i)
  54.                 end
  55.             write('Press ''Enter'' to quit.');
  56.             readln
  57.         end.
  58.  
  59.  
  60. }
  61.  
  62. unit flex;
  63.  
  64. interface
  65.  
  66.     type
  67.  
  68.         FlexData = word;
  69.  
  70.         FlexN = ^FlexNode;
  71.         FlexNode = record
  72.         { private: }
  73.             next, prev : FlexN;
  74.         { public: }
  75.             data : FlexData
  76.         end;
  77.  
  78.         FlexCompare = function (var data1, data2) : integer;
  79.  
  80.         FlexL = ^FlexList;
  81.         FlexList = object
  82.         { private: }
  83.             front, current, rear : FlexN;
  84.         { public, read only: }
  85.             curNum, nodes, sizeofData, sizeofNode,
  86.         { public: }
  87.             sizeofLastPack, sizeofLastPackPtrs : word;
  88.             ok : boolean;
  89.             constructor init(dataSize : word);
  90.             constructor unpack(cellSize, cells : word;
  91.                             var arrayBuf);
  92.             procedure   clear;
  93.             procedure   push(var data);
  94.             procedure   pushN(n : FlexN);
  95.             procedure   pop(var data);
  96.             function    popN : FlexN;
  97.             procedure   top(var data);
  98.             function    frontD : pointer;
  99.             procedure   insQ(var data);
  100.             procedure   insQN(n : FlexN);
  101.             function    rearD : pointer;
  102.             procedure   mkcur(loc : word);
  103.             function    currentD : pointer;
  104.             procedure   ins(var data);
  105.             procedure   insN(n : FlexN);
  106.             procedure   insSort(var data;
  107.                             compare : FlexCompare);
  108.             procedure   insSortN(n : FlexN;
  109.                             compare : FlexCompare);
  110.             procedure   del(var data);
  111.             function    delN : FlexN;
  112.             function    next(var data) : boolean;
  113.             function    nextD(var d : pointer) : boolean;
  114.             function    prev(var data) : boolean;
  115.             function    prevD(var d : pointer) : boolean;
  116.             procedure   get(var data);
  117.             procedure   put(var data);
  118.             procedure   store(var data; location : word);
  119.             procedure   recall(var data; location : word);
  120.             function    find(var data; compare : FlexCompare)
  121.                             : boolean;
  122.             procedure   sort(compare : FlexCompare);
  123.             function    pack : pointer;
  124.             function    packPtrs : pointer;
  125.             destructor  done;
  126.         end;
  127.